#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		for (int i = 0; i < n; i++)
			cin >> a[i];

		sort(a.begin(), a.end(), [](int x, int y) {
			if ((x ^ y) < 4)
				return x < y;
		});

		for (int i : a)
			cout << i << " ";
		cout << endl;
	}
	return 0;
}
